<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        window.onload=function(){
          var oName=document.getElementById('name');
          var oAge=document.getElementById('age');
          var oTab=document.getElementById('tab1');
          var oBtn=document.getElementById('btn1');
          var id=oTab.tBodies[0].rows.length+1;
          oBtn.onclick=function(){
            //alert(oTab.tBodies[0].rows[1].cells[1].innerHTML);
                  var oTr=document.createElement('tr');
                  var oTd=document.createElement('td');
                  oTd.innerHTML=id++;
                  oTr.appendChild(oTd);

                  var oTd=document.createElement('td');
                  oTd.innerHTML=oName.value;
                  oTr.appendChild(oTd);

                  var oTd=document.createElement('td');
                  oTd.innerHTML=oAge.value;
                  oTr.appendChild(oTd);

                  var oTd=document.createElement('td');
                  oTd.innerHTML='<a href="javascript:;">删除</a>';
                  oTr.appendChild(oTd);

                  oTab.tBodies[0].appendChild(oTr);

                  oTd.getElementsByTagName('a')[0].onclick=function(){
                    oTab.tBodies[0].removeChild(this.parentNode.parentNode);
                  };
          };


        };
    </script>
</head>
<body>
姓名 <input type="text" id="name">
年龄 <input type="text" id="age">
<input type="button" value="添加" id="btn1">
<table  border="1" id="tab1" width="500px;">
    <thead>
    <tr>
        <td>序号</td>
        <td>姓名</td>
        <td>年龄</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>1</td>
        <td>张三</td>
        <td>24</td>
        <td></td>
    </tr>
    <tr>
        <td>2</td>
        <td>赵四</td>
        <td>27</td>
        <td></td>
    </tr>
    <tr>
        <td>3</td>
        <td>王峰</td>
        <td>25</td>
        <td></td>
    </tr>
    <tr>
        <td>4</td>
        <td>王五</td>
        <td>34</td>
        <td></td>
    </tr>
    </tbody>
</table>
</body>
</html>